function getStateCheckbox(ctrl)
{
    var myCheckBox = document.getElementById(ctrl);
    if (myCheckBox.checked)
        myCheckBox.value = "true";
    else
        myCheckBox.value = "false";

    return myCheckBox.value;
}

function agregarrol(){
	var nombre = document.getElementById('nombres').value;
	var es_rol_padre = getStateCheckbox(document.getElementById('es_rol_padre').name);
	var activo = getStateCheckbox(document.getElementById('activo').name);
         $.ajax({
             dataType:"html",
             type:"POST",
             url:"/INFACOV/public/acceso/rol/agregarol",
             data:'nombre=' + nombre +'&es_rol_padre=' + es_rol_padre +'&activo=' + activo,
             
             beforeSend: function(objeto){				
					waitingDialog({title: "GUARDANDO", message: "Espere Mientras Se Guardan Los Datos"});				
			 		},
			 		
             success: function(requestData){ 	//Llamada exitosa
             	//id_consulta = requestData;
              },
            error: function(requestData, strError, strTipoError){
			  		alert("Error " + strTipoError +': ' + strError ); //En caso de error mostraremos un alert
            },
           	complete: function(requestData, textStatus){ //fin de la llamada ajax.
           		if(textStatus == 'success'){
						closeWaitingDialog();				
					}
					else if(textStatus == 'error'){	
						alert('Error al guardar: Intentelo Nuevamente Por Favor');
						$("#loadingScreen").dialog('close');
					}						
            }
          });
}

//ventana de loading
$(document).ready(function() {
	// create the loading window and set autoOpen to false
	$("#loadingScreen").dialog({
		autoOpen: false,	// set this to false so we can manually open it
		dialogClass: "loadingScreenWindow",
		closeOnEscape: false,
		draggable: false,
		width: 340,
		minHeight: 50,
		modal: true,
		buttons: {},
		resizable: false,
		open: function() {
			// scrollbar fix for IE
			$('body').css('overflow','hidden');
		},
		close: function() {
			// reset overflow
			$('body').css('overflow','auto');
		}
	}); // end of dialog
	
});

function waitingDialog(waiting) { // I choose to allow my loading screen dialog to be customizable, you don't have to
	$("#loadingScreen").html(waiting.message, '' != waiting.message ? waiting.message : 'Please wait...');
	$("#loadingScreen").dialog('option', 'title', waiting.title , '' != waiting.title ? waiting.title : 'Loading');
	$("#loadingScreen").dialog('open');
}

function closeWaitingDialog(){
	$("#loadingScreen").dialog('close');
	$("#dialogmessage").dialog('open');	
}

$(document).ready(function(){
		//$( "#dialog:ui-dialog" ).dialog( "destroy" );	
		$( "#dialogmessage" ).dialog({
			autoOpen: false,
			modal: true,
			closeOnEscape: false,
			draggable: true,
			buttons: {
				Ok: function(){
				window.top.location.href='/INFACOV/public/acceso/index/ingresado';
					$(this).dialog("close");					
				}
			}
		}).parent('.ui-dialog').find('.ui-dialog-titlebar-close').hide();
});

function salir(){
	window.top.location.href='/INFACOV/public/acceso/index/ingresado';
};

function validarFormulario(obj){
    if(jQuery("#form_valida").validationEngine('validate')){
    	return true;
    }else return false;
};